package com.smarthome.web.property.controller.account;

import java.util.List;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.smarthome.core.account.AccountTypeService;
import com.smarthome.domain.bean.ShAccountType;
import com.smarthome.domain.bean.ShAccountTypeResource;
import com.smarthome.domain.common.Result;
import com.smarthome.domain.vo.boss.Combobox;
import com.smarthome.domain.vo.boss.DataGrid;
import com.smarthome.domain.vo.boss.PageHelper;

@Controller
@RequestMapping(value="/accountType")
public class AccountTypeController {
	
	@Resource
	private AccountTypeService accountTypeService;
	
	@RequestMapping("/dataGrid")
	@ResponseBody
	public DataGrid dataGrid(ShAccountType accountType,PageHelper page){
		return accountTypeService.queryDataGrid(accountType, page);
	}
	
	@RequestMapping("/typeFeature")
	@ResponseBody
	public List<ShAccountTypeResource> queryTypeFeature(Long id){
		return accountTypeService.queryTypeFeaturesByTypeId(id);
	}
	
	@RequestMapping("/combobox")
	@ResponseBody
	public List<Combobox> getCombobox(){
		return accountTypeService.getCombobox();
	}
	
	@RequestMapping("/addPage")
	public String addPage(){
		return "/account/accountTypeAdd";
	}
	
	@RequestMapping("/add")
	@ResponseBody
	public Result add(ShAccountType accountType,Long[] features){
		accountTypeService.add(accountType, features);
		return Result.success("添加成功！");
	}
	
	@RequestMapping("/editPage")
	public String editPage(HttpServletRequest request,Long id){
		ShAccountType accountType=accountTypeService.queryAccountTypeById(id);
		request.setAttribute("accountType", accountType);
		return "/account/accountTypeEdit";
	}
	
	@RequestMapping("/edit")
	@ResponseBody
	public Result edit(ShAccountType accountType,Long[] features){
		accountTypeService.edit(accountType, features);
		return Result.success("更改成功！");
	}
	
	@RequestMapping("/delete")
	@ResponseBody
	public Result delete(Long id){
		accountTypeService.delete(id);
		return Result.success("删除成功！");
	}
}
